package com.lingchen.service.impl;

import com.lingchen.dao.CourseDao;
import com.lingchen.entity.Course;
import com.lingchen.service.CourseService;
import com.lingchen.utils.IdGen;
import com.lingchen.utils.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * Author    lingchen
 * Email     838878458@qq.com
 * Time      2018/2/26
 * Function  科目
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class CourseServiceImpl implements CourseService {
    @Autowired
    private CourseDao courseDao;

    public int insertCourse(Course... courses) {
        for (Course c : courses) {
            c.setId(IdGen.uuid());
            //计算总分
            if (c.getScore() != 0 && c.getCount() != 0) {
                c.setTotalScore(c.getScore() * c.getCount());
            }
        }
        return courseDao.insertCourse(courses);
    }

    public Course selectCourseById(String id) {
        return courseDao.selectCourseById(id);
    }

    public List<Course> selectCourse() {
        return courseDao.selectCourse();
    }
}
